package conteoller;

import biz.TypeBiz;
import com.google.gson.Gson;
import dao.TypetbDAO;
import entity.TypetbEntity;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/*
 * @Description锛�
 *       绫诲瀷鏁版嵁澶勭悊
 * @Author: JiangFan
 * @Date: 2019/3/9
 * @Time锛�9:55
 */
@WebServlet("/types")
public class TypeServlet extends BaseServlet {
    TypeBiz tb=new TypeBiz ();
    TypetbEntity te=new TypetbEntity ();
    /** 鏌ヨ鎵�鏈夌被鍨�
     * @param req
     * @param reps
     * @return
     */
    public String queryTypeAll (HttpServletRequest req, HttpServletResponse reps)
            throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
        List<TypetbEntity> list=tb.queryTypeAll ();
        Gson gson=new Gson ();
        String json=gson.toJson (list);
        return json;
    }

    /** 娣诲姞绫诲瀷鏄惁瀛樺湪
     * @param req
     * @param resp
     * @return 杩斿洖绌哄�硷紝涓嶅奖鍝嶉〉闈㈣烦杞�
     */
    public String queryTypeOne(HttpServletRequest req,HttpServletResponse resp) throws IOException {
        //鍙栫紪鍙�
        String type=req.getParameter ("txtType");
        //璋冪敤Biz鏌ヨ鏂规硶,鏌ヨ棰滆壊鏄惁鍙敤
        try {
            boolean ce=tb.checkType (type);
            if (ce){
                resp.getWriter ().write ("绫诲瀷鍙敤");
            }else {
                resp.getWriter ().write ("绫诲瀷宸插瓨鍦�");
            }
        }catch (Exception e){
            //鍝嶅簲閿欒娑堟伅鏂囨湰
            resp.getWriter ().write ("绫诲瀷涓嶅彲鐢�");
        }
        return null;
    }
}
